import 'dart:ui';

import 'package:camera/camera.dart';
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/cupertino.dart' hide Action;
import 'package:flutter/material.dart';
import 'package:multi_image_picker/multi_image_picker.dart';
import 'package:www.znpigai.teacher/home_page/homework_list_component/item/state.dart';

import '../global_store/state.dart';

class AnswerEditState implements GlobalBaseState, Cloneable<AnswerEditState> {
  CameraDescription camera;
  CameraController controller;
  bool aiCommitted = false;

  TextEditingController titleEditController;
  FocusNode focusNodeTitle;
  TextEditingController contentEditController;
  FocusNode focusNodeContent;
  List<Asset> photos;
  int currentOcrIndex = -1;
  bool isTitle = true;
  String aliToken = '';
  HomeworkState answer;

  @override
  AnswerEditState clone() {
    return AnswerEditState()
      ..themeColor = themeColor
      ..userInfo = userInfo
      ..camera = camera
      ..controller = controller
      ..titleEditController = titleEditController
      ..focusNodeTitle = focusNodeTitle
      ..contentEditController = contentEditController
      ..focusNodeContent = focusNodeContent
      ..currentOcrIndex = currentOcrIndex
      ..isTitle = isTitle
      ..answer = answer
      ..aliToken = aliToken
      ..aiCommitted = aiCommitted
      ..photos = photos;
  }

  @override
  Color themeColor;

  @override
  Map<String, dynamic> userInfo;
}

AnswerEditState initState(Map<String, dynamic> args) {
  if (args == null) {
    args = {};
  }

  final AnswerEditState state = AnswerEditState()
    ..answer = args['answer']
    ..titleEditController = TextEditingController()
    ..focusNodeTitle = FocusNode()
    ..contentEditController = TextEditingController()
    ..focusNodeContent = FocusNode()
    ..photos = [];
  state.titleEditController.text = state.answer.title;
  state.contentEditController.text = state.answer.content;

  return state;
}
